package com.gitee.hermer.engine.jars.app.sdk.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.gitee.hermer.boot.jee.commons.collection.CollectionUtils;
import com.gitee.hermer.boot.jee.commons.log.UtilsContext;
import com.gitee.hermer.boot.jee.commons.utils.StringUtils;
import com.gitee.hermer.engine.jars.core.annotate.EngineComponent;
import com.gitee.hermer.engine.jars.core.domain.EngineConstant;

public class EngineJobBeanFactoryPostProcessor extends UtilsContext implements ApplicationContextAware, BeanFactoryPostProcessor {
	
	private String[] basePackages;
	public EngineJobBeanFactoryPostProcessor(String[] basePackages){
		this.basePackages = basePackages;
	}
	
	
	private ApplicationContext applicationContext;

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		EngineAnnotationScanner scanner= EngineAnnotationScanner.getScanner((BeanDefinitionRegistry) beanFactory, EngineComponent.class);
		scanner.setResourceLoader(this.applicationContext);
		info("注解扫描|basePackages[%s] -> @EngineComponent",CollectionUtils.join(basePackages, EngineConstant.STR_COMMA));
		scanner.doScan(basePackages);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}

}
